import lombok.SneakyThrows;
import org.junit.Test;

import java.util.concurrent.TimeUnit;

/**
 * @author Liangyaoyun
 */
public class testThread {
    //继承方法多线程
    private static class MyThread extends Thread {
        @Override
        public void run() {
            for (int i = 1; i < 10; i++) {
                System.out.println("梁耀云打了姜英博" + i + "巴掌");
            }
        }
    }

    //实现方法多线程
    private static class MyThread01 implements Runnable {
        @Override
        public void run() {
            for (int i = 1; i < 10; i++) {
                System.out.println("姜英博叫了梁耀云" + i + "次主人");
            }
        }
    }

    @SneakyThrows
    @Test
    public void test01() {
        new MyThread().start();

        TimeUnit.SECONDS.sleep(5L);

    }

    @SneakyThrows
    @Test
    public void test02() {
        MyThread myThread = new MyThread() {
            @Override
            public void run() {
                for (int i = 0; i < 10; i++) {
                    System.out.println("姜英博为梁耀云生了 " + i + "个孙子");
                }
                ;
            }
        };
        myThread.start();
        TimeUnit.SECONDS.sleep(5L);
    }

    //继承线程方法测试
    @Test
    @SneakyThrows
    public void test03(){
        new Thread(new MyThread01()).start();
        TimeUnit.SECONDS.sleep(5L);
    }
    //与上面的继承跟实现线程是一样的，只不过这样写简单一点
    @Test
    @SneakyThrows
    public void test04(){
        new Thread(()->{
            for (int i = 11; i < 20; i++) {
                System.out.println(i);
            }
        }).start();

    }
}

